package com.ywjh.inter.work;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.ywjh.inter.common.MemKey;
import com.ywjh.inter.common.SystemConfig;
import com.ywjh.inter.conn.MemcacheConn;
import com.ywjh.inter.dao.VersionDAO;
import com.ywjh.inter.entity.VersionEntity;

import net.sf.json.JSONObject;

public class Version {

	public void publish(Connection conn) throws SQLException {
		VersionDAO versionDAO = new VersionDAO();
		List<VersionEntity> doclist = versionDAO.listDoc(conn);
		List<VersionEntity> patlist = versionDAO.listPatient(conn);
		if (!doclist.isEmpty()) {
			VersionEntity doc = doclist.get(0);
			JSONObject version=new JSONObject();
			version.put("title", doc.getTitle());
			version.put("content", doc.getContent());
			version.put("version_code", doc.getVersionCode());
			version.put("version_name", doc.getVersionName());
			version.put("is_force", doc.getIsForce());
			version.put("url", SystemConfig.CDN_DOMAIN+doc.getFilePath());
			MemcacheConn.getInstance().put(MemKey.APP_DOC, version.toString());
		}
		if (!patlist.isEmpty()) {
			VersionEntity patient = patlist.get(0);
			JSONObject version=new JSONObject();
			version.put("title", patient.getTitle());
			version.put("content", patient.getContent());
			version.put("version_code", patient.getVersionCode());
			version.put("version_name", patient.getVersionName());
			version.put("is_force", patient.getIsForce());
			version.put("url", SystemConfig.CDN_DOMAIN+patient.getFilePath());
			MemcacheConn.getInstance().put(MemKey.APP_PATIENT, version.toString());
		}
	}

}
